package com.sjy.web.controller.ship;

import com.sjy.common.annotation.Log;
import com.sjy.common.core.controller.BaseController;
import com.sjy.common.core.domain.AjaxResult;
import com.sjy.common.core.page.TableDataInfo;
import com.sjy.common.core.redis.RedisCache;
import com.sjy.common.enums.BusinessType;
import com.sjy.common.utils.poi.ExcelUtil;
import com.sjy.ship.domain.ShipInfo;
import com.sjy.ship.service.IShipInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 船舶信息Controller
 * 
 * @author lzm
 * @date 2023-06-14
 */
@RestController
@RequestMapping("/ship/info")
public class ShipInfoController extends BaseController
{
    @Autowired
    private IShipInfoService shipInfoService;

    /**
     * 查询船舶信息列表
     */
    @PreAuthorize("@ss.hasPermi('ship:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShipInfo shipInfo)
    {
        startPage();
        List<ShipInfo> list = shipInfoService.selectShipInfoList(shipInfo);
        return getDataTable(list);
    }
    /**
     * 查询船舶信息缓存列表
     */
    @PreAuthorize("@ss.hasPermi('ship:info:list')")
    @GetMapping("/cacheList")
    public AjaxResult cacheList()
    {
        List<ShipInfo> list = shipInfoService.selectShipInfoCacheList(false);
        return success(list);
    }

    /**
     * 导出船舶信息列表
     */
    @PreAuthorize("@ss.hasPermi('ship:info:export')")
    @Log(title = "船舶信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShipInfo shipInfo)
    {
        List<ShipInfo> list = shipInfoService.selectShipInfoList(shipInfo);
        ExcelUtil<ShipInfo> util = new ExcelUtil<ShipInfo>(ShipInfo.class);
        util.exportExcel(response, list, "船舶信息数据");
    }

    /**
     * 获取船舶信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('ship:info:query')")
    @GetMapping(value = "/{shipId}")
    public AjaxResult getInfo(@PathVariable("shipId") Long shipId)
    {
        return success(shipInfoService.selectShipInfoByShipId(shipId));
    }

    /**
     * 新增船舶信息
     */
    @PreAuthorize("@ss.hasPermi('ship:info:add')")
    @Log(title = "船舶信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody ShipInfo shipInfo)
    {
        return shipInfoService.insertShipInfo(shipInfo);
    }

    /**
     * 修改船舶信息
     */
    @PreAuthorize("@ss.hasPermi('ship:info:edit')")
    @Log(title = "船舶信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody ShipInfo shipInfo)
    {
        return shipInfoService.updateShipInfo(shipInfo);
    }

    /**
     * 删除船舶信息
     */
    @PreAuthorize("@ss.hasPermi('ship:info:remove')")
    @Log(title = "船舶信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{shipIds}")
    public AjaxResult remove(@PathVariable Long[] shipIds)
    {
        return shipInfoService.deleteShipInfoByShipIds(shipIds);
    }
}
